package testing;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import model.Employee;
import model.Gender;

import dao.EmployeeDAO;

public class InsertEmployee {
	public static void main(String[] args) {
		
		for (int i = 1; i <=5000; i++) {
			
			new Thread() {
				public void run() {
					EntityManagerFactory emf = Persistence
					.createEntityManagerFactory("employee");
					
					EmployeeDAO empDAO = new EmployeeDAO();
					
					while(true) {
						
						empDAO.setEntityManagerFactory(emf);
						
						Employee e = new Employee();
						//e.setId(25);
						e.setFirstName("Pham");
						e.setLastName("Xuan Loc" + System.currentTimeMillis());
						e.setGender(Gender.Male);
						
						empDAO.insert(e);
						
						try {
							Thread.sleep(5000);
						} catch (InterruptedException e1) {
							e1.printStackTrace();
						}
					}
				}
			}.start();
			
		}
		
		
		
//		EntityManagerFactory emf = Persistence
//		.createEntityManagerFactory("employee");
//		
//		EmployeeDAO empDAO = new EmployeeDAO();
//		
//		empDAO.setEntityManagerFactory(emf);
//		
//		Employee e = new Employee();
//		//e.setId(25);
//		e.setFirstName("Pham");
//		e.setLastName("Xuan Loc" + System.currentTimeMillis());
//		e.setGender(Gender.Male);
//		
//		empDAO.insert(e);
	}
}
